/**
 * 开放业务
 */


class Open {
    // 用户登录
    async login(ctx) {
        const { server, params } = ctx;
        const { account, password } = params;
        const _tUser = await server.model.User.findOne({
            where: {
                account,
                password
            }
        })
        if (_tUser && _tUser.pk) {
            const tUser = _tUser.toJSON();
            // 生成token
            const authtoken = await server.helper.context.token.create(tUser)
            tUser.authtoken = authtoken;
            return {
                code: 200,
                result: tUser,
                msg: 'success'
            }
        } else {
            return {
                code: 400,
                msg: 'account or password error'
            }
        }
    }
}

export default Open